//
// Created by seeed on 25-8-15.
//

#include "button.h"
#include <esp32-hal-gpio.h>

#define BUTTON_STATE_NORMAL LOW // 按钮常态
#define BUTTON_STATE_PRESS HIGH // 按钮按下状态

// Button类构造函数，初始化按钮引脚
Button::Button(const uint8_t btn_pin) : btn_pin(btn_pin) {
    pinMode(btn_pin, INPUT);    // 设置按钮引脚为输入模式
}

// 检查按钮是否被按下
bool Button::isPressed() const {
    return digitalRead(btn_pin) == BUTTON_STATE_PRESS;
}

// 检查按钮是否被释放
bool Button::isReleased() const {
    return digitalRead(btn_pin) == BUTTON_STATE_NORMAL;
}
